<template>
  <el-card shadow="always" :body-style="{ padding: '15px' }">
    <!-- card body -->
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <!-- 适用广泛的基础单选 v-model 的值为当前被选中的 el-option 的 value 属性值 -->
        <el-select v-model="categoryStore.c1Id" @change="c1Handler" :disabled="scene!=0">
          <el-option
            :label="c1.name"
            :value="c1.id"
            v-for="(c1, index) in categoryStore.C1List"
            :key="c1.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select v-model="categoryStore.c2Id" @change="c2Handler" :disabled="scene!=0">
          <el-option :label="c2.name" :value="c2.id" v-for="(c2,index) in categoryStore.C2List" :key="c2.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="categoryStore.c3Id" :disabled="scene!=0">
          <el-option :label="c3.name" :value="c3.id" v-for="(c3,index) in categoryStore.C3List" :key="c3.id"/>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
// 引入组合式API
import { onMounted } from "vue";
// 引入仓库
import useCategoryStore from "@/stores/category";

let categoryStore = useCategoryStore();
// 组件挂载时获取一级分类数据
onMounted(() => {
  categoryStore.getC1List();
});
// 一级分类的id发生改变时触发change事件,获取二级分类的数据
const c1Handler = ()=>{
    categoryStore.getC2List()
}
// 二级分类的id发生改变时触发change事件,获取三级分类的数据
const c2Handler = ()=>{
    categoryStore.getC3List()
}

defineProps(['scene'])
</script>

<style scoped>
</style>